Skip to content

Conversation

@arihant2math
Copy link
Collaborator

@arihant2math arihant2math commented Jan 5, 2026

Implements socket syscalls (i.e. socket, accept, connect, bind, etc.) and unix sockets. Also stubs out part of a TCP socket implementation.

@arihant2math arihant2math force-pushed the socket branch 25 times, most recently from efcec20 to 14b4026 Compare January 7, 2026 18:48
@arihant2math arihant2math marked this pull request as ready for review January 7, 2026 18:48
@arihant2math arihant2math mentioned this pull request Jan 7, 2026
6 tasks
Copy link
Owner

@hexagonal-sun hexagonal-sun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some minor comments. Hopefully they'll fix things up nicely. One final point.. perhaps it's worth putting all this code under net, rather than socket? That seems to be the idiomatic name that most kernels use for this kind of code.


impl TcpSocket {
pub fn new() -> Self {
let rx_buffer = SocketBuffer::new(vec![0; 4096]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using the heap, maybe dedicate a ClaimedPage here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SocketBuffer needs something that can be converted into a ManagedSlice, so I have to give it an owned vec. Trying to give it a borrowed slice runs into issues because the slice would be given a lifetime of 'static

handle,
local_endpoint: SpinLock::new(None),
backlogs: SpinLock::new(Vec::new()),
num_backlogs: AtomicUsize::new(0),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I quite get why we track this separately? Couldn't we call backlogs.len()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to reduce calls into the SpinLock for performance.

}

#[async_trait]
impl SocketOps for UnixSocket {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost wonder whether we make a bit of an architectural change here and consider splitting the trait into two types.. a listening socket and a connected socket? Feels like this might make things easier.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the registry would only contain listening sockets.

if *self.rd_shutdown.lock_save_irq() {
return Ok(0);
}
self.inbox.copy_to_user(buf, count).await
Copy link
Owner

@hexagonal-sun hexagonal-sun Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once thing to note, SeqPacket and Datagram sockets will not preserve message boundaries with the kbuf, it's just a stream of bytes; a perfect fit for Stream sockets.

We need to think about how we can preserve message boundaries.

@arihant2math arihant2math force-pushed the socket branch 2 times, most recently from d2a23d8 to d17077d Compare January 14, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants